package kayao.client.scene.objects;

import javax.microedition.khronos.opengles.GL10;

import kayao.client.R;
import kayao.client.scene.PhysicsController;

import com.chopsticks3d.scene.Material;
import com.chopsticks3d.scene.Mesh;
import com.chopsticks3d.scene.MeshNode;
import com.chopsticks3d.scene.Texture;
import com.chopsticks3d.scene.shape.Cube;

public class BuildingNode extends PhysicalNode {
	private static final Mesh MESH_BUILDING = new Cube();
	private static final Texture TEXTURE_SKYSCRAPE = new Texture(R.drawable.skyscrape);
	
	private MeshNode mBuildingNode;
	private Boolean mPhysicsInitialized = false;
	
	public BuildingNode() {
		// Create the scene of the building
		Material buildingMaterial = new Material();
		buildingMaterial.setAmbient(1, 1, 1, 1);
		mBuildingNode = new MeshNode(MESH_BUILDING, TEXTURE_SKYSCRAPE, buildingMaterial);
		mBuildingNode.setTranslationY(0.5f);
		setScale(14, 14, 14);
		
		addChild(mBuildingNode);
	}
	
	@Override
	public void onDraw(GL10 gl) {
		if (!mPhysicsInitialized) {
			mBodyId = PhysicsController.createStaticBox(mX, mZ, getScaleX(), getScaleZ());			
			mPhysicsInitialized = true;
		}
		super.onDraw(gl);
	}
}
